﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTEngine
{
    public class FancyCorridor : PatternRoom
    {
        //static constructor
        static FancyCorridor()
        {
            string s = Properties.Resources.FancyCorridors;
            string[] lines = s.Split('\r', '\n');
            string pm = "";
            foreach (string line in lines)
            {
                if (line.Trim() == "")
                    continue;
                if (line.StartsWith("*"))
                {
                    string[] tokens = line.Split(',');
                    _patternMaps.Add(pm);
                    int idx = _patternMaps.Count - 1;
                    int startCon = Int32.Parse(tokens[1]);
                    int endCon = Int32.Parse(tokens[2]);
                    _startConnectors[idx] = startCon;
                    _endConnectors[idx] = endCon;
                    pm = "";
                }
                else
                {
                    if (pm != "")
                        pm += ",";
                    pm += line;
                }
            }
        }

        //constructor
        public FancyCorridor()
            : base()
        {
            UseConnectorPoints = true;
        }

        //clone
        public override Room Clone()
        {
            return new FancyCorridor();
        }

        public override string PatternMap
        {
            get
            {
                if (_pmUsed == -1)
                {
                    _pmUsed = Globals.RandomIntFromTo(0, _patternMaps.Count - 1);
                    StartConnector = _startConnectors[_pmUsed];
                    EndConnector = _endConnectors[_pmUsed];
                }
                return _patternMaps[_pmUsed];
            }
        }

        public override bool IsCorridor
        {
            get
            {
                return true;
            }
        }

        //private members
        private static List<string> _patternMaps = new List<string>();
        private static Dictionary<int, int> _startConnectors = new Dictionary<int, int>();
        private static Dictionary<int, int> _endConnectors = new Dictionary<int, int>();
        private int _pmUsed = -1;
    }
}
